﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;
using System.Threading;
using Game.Controls;

namespace Game.Frames
{
    public partial class Main : Form
    {
        #region Initialisieren
        //Soundplayer
        public SoundPlayer menuPlayer   = new SoundPlayer(Game.Properties.Resources.MenuLoop);
        public SoundPlayer gamePlayer   = new SoundPlayer(Game.Properties.Resources.GameLoop);
        public SoundPlayer winPlayer    = new SoundPlayer(Game.Properties.Resources.WinSound);
        
        public Main()
        {
            InitializeComponent();
            
            //Panel in Frame anpassen
            panelMain.Size      = this.Size;
            panelMain.Location  = new Point(0, 0);

            Session.fenster     = this;

            //Controls leeren und Hauptmenu einfügen
            panelMain.Controls.Clear();
            panelMain.Controls.Add(new controlMenu(this));
            panelMain.Controls[0].Location = new Point(0, 0);

            //Schriften initialisieren
            Session.loadFont();
        }
        #endregion

        #region Controlwechsel
        //Bisheriges Kontrol freigeben und Menu anzeigen
        public void showMenu()
        {
            controlMenu neu = new controlMenu(this);

            foreach (Control c in panelMain.Controls)
                c.Dispose();
            panelMain.Controls.Clear();

            panelMain.Controls.Add(neu);
            panelMain.Controls[0].Location = new Point(0, 0);
        }

        //Bisheriges Kontrol freigeben und Tutorial anzeigen
        public void showTutorial()
        {
            controlTutorial neu = new controlTutorial(this);

            foreach (Control c in panelMain.Controls)
                c.Dispose();
            panelMain.Controls.Clear();

            panelMain.Controls.Add(neu);
            panelMain.Controls[0].Location = new Point(0, 0);
        }

        //Bisheriges Kontrol freigeben und Level Auswahl anzeigen
        public void showLevelAuswahl()
        {
            controlLevelAuswahl neu = new controlLevelAuswahl(this);

            foreach (Control c in panelMain.Controls)
                c.Dispose();
            panelMain.Controls.Clear();

            panelMain.Controls.Add(neu);
            panelMain.Controls[0].Location = new Point(0, 0);
            panelMain.Controls[0].Focus();
        }

        //Editor anzeigen
        public void showEditor(Size dimensions)
        {
            if (Session.soundEnabled)
            {
                menuPlayer.Stop();
            }

            if(Session.frmEditor != null)
                Session.frmEditor.Close();

            Session.frmEditor = new Editor(new Size(dimensions.Width, dimensions.Height));
            Session.frmEditor.Show();
        }

        //Bisheriges Kontrol freigeben und Spiel starten
        public void showGame(string file)
        {
            controlGame neu = new controlGame(this, file);

            foreach (Control c in panelMain.Controls)
                c.Dispose();
            panelMain.Controls.Clear();

            panelMain.Controls.Add(neu);
            panelMain.Controls[0].Location = new Point(0, 0);
            panelMain.Controls[0].Focus();
        }

        //Bisheriges Kontrol freigeben und Credits zeigen
        public void showCredits()
        {
            controlCredits neu = new controlCredits(this);

            foreach (Control c in panelMain.Controls)
                c.Dispose();
            panelMain.Controls.Clear();

            panelMain.Controls.Add(neu);
            panelMain.Controls[0].Location = new Point(0, 0);
        }
        #endregion

        #region Musik abspielen
        //ButtonSounds
        public void playMenuMusic()
        {
            gamePlayer.Stop();
            menuPlayer.PlayLooping();
        }

        public void playGameMusic()
        {
            menuPlayer.Stop();
            gamePlayer.PlayLooping();
        }

        public void stopGameMusic()
        {
            gamePlayer.Stop();
        }

        public void playWinMusic()
        {
            gamePlayer.Stop();
            winPlayer.Play();
        }
        #endregion
    }
}
